import { Logger } from "../../../engine/Logger";
import { RoomConfig } from "../../config/RoomConfig";
import RoomConfig_Mj from "../../config/RoomConfig_Mj";
import roomconfig_create from "./roomconfig_create";

const { ccclass, property } = cc._decorator;

@ccclass
export default class mj_create extends roomconfig_create {

    public roomConfig: RoomConfig_Mj;
    
    private dianpao_toggleContainer: cc.ToggleContainer;

    onEnable(): void {
        this.roomConfig = RoomConfig_Mj.createConfig()
        super.onEnable()

        for (let i = 0; i < RoomConfig_Mj.renshuConfig.length; i++) {
            let txt: cc.Label = this.getChild(this.renshu_toggleContainer.node, "txt" + i, cc.Label)
            txt.string = RoomConfig_Mj.renshuConfig[i] + "人"
        }
        for(let i=0; i<RoomConfig_Mj.difenConfig.length; i++){
            let txt: cc.Label = this.getChild(this.difen_toggleContainer.node, "txt" + i, cc.Label)
            txt.string = RoomConfig_Mj.difenConfig[i] + "分"
        }

        this.dianpao_toggleContainer = this.getChild(this.node, "view/content/dianpao/dianpao_toggleContainer", cc.ToggleContainer)
        this.setToggleContainerIndex(this.dianpao_toggleContainer, 0)
    }

    protected update(dt: number): void {
        let renshuIndex: number = this.getToggleContainerIndex(this.renshu_toggleContainer)
        let renshu: number = RoomConfig_Mj.renshuConfig[renshuIndex]
        for (let i = 0; i < RoomConfig_Mj.jushuConfig.length; i++) {
            let txtJu: cc.Label = this.getChild(this.jushu_toggleContainer.node, "txtJu" + i, cc.Label)
            let tempCost: number = RoomConfig_Mj.fangfeiConfig[renshuIndex][i]
            this.roomConfig.cost_type = this.getToggleContainerIndex(this.fangfei_toggleContainer)
            if (this.roomConfig.cost_type == RoomConfig.cost_type.pingjun) {
                tempCost = tempCost / renshu
            }
            txtJu.string = "" + RoomConfig_Mj.jushuConfig[i] + "局(" + tempCost + "钻石)"
        }
    }


    public getRoomConfig() {
        super.getRoomConfig()
        let renshuIndex: number = this.getToggleContainerIndex(this.renshu_toggleContainer)
        this.roomConfig.renshu = RoomConfig_Mj.renshuConfig[renshuIndex]
        let jushuIndex: number = this.getToggleContainerIndex(this.jushu_toggleContainer)
        this.roomConfig.jushu = RoomConfig_Mj.jushuConfig[jushuIndex]
        this.roomConfig.cost = RoomConfig_Mj.fangfeiConfig[renshuIndex][jushuIndex]
        let difenIndex: number = this.getToggleContainerIndex(this.difen_toggleContainer)
        this.roomConfig.difen = RoomConfig_Mj.difenConfig[difenIndex]
        this.roomConfig.cost_type = this.getToggleContainerIndex(this.fangfei_toggleContainer)

        this.roomConfig.dianpao_type = this.getToggleContainerIndex(this.dianpao_toggleContainer)

        // this.roomConfig.fangpao_type =  this.getToggleContainerIndex(this.fangfei_toggleContainer)

        Logger.log("mj_create.getRoomConfig====", this.roomConfig)
        return this.roomConfig;
    }


    onDisable(): void {
        super.onDisable()
    }

}
